home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / WINDOSIO.ZIP / EXAMPL7.C < prev    next >
Text File  |  1992-12-26  |  4KB  |  181 lines

  1. /***************************************************************************
  2. * EXAMPL7.C
  3. * Simple graphics demo
  4. * ****************************************************************************/
  5. #ifdef NOWINDOWS
  6. #include "e:\include\graph.h"
  7. #include "e:\include\stdio.h"
  8. #include "e:\include\conio.h"
  9. #include "e:\include\stdlib.h"
  10. #include "e:\include\memory.h"
  11. #include "e:\include\math.h"
  12. #include "e:\include\string.h"
  13. #else
  14. #include <Windows.h>
  15. #include "WinDosIO.h"
  16. long far pascal WndProc(HWND, WORD, WORD, LONG);
  17. HWND idWindow;
  18. HANDLE hInst;
  19. #include <stdlib.h>
  20. #include <memory.h>
  21. #include <alloc.h>
  22. #include <math.h>
  23. #include <string.h>
  24. #endif
  25.  
  26.  
  27.  
  28. char buffer[80];
  29. int i,j;
  30.  
  31.  
  32.  
  33. #ifdef NOWINDOWS
  34. main()
  35.   {
  36. #else
  37. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  38.            LPSTR lpszCmdline, int cmdshow)
  39.  
  40.  {
  41.     HWND hwnd;
  42.     MSG msg;
  43.     WNDCLASS wc;
  44.     RECT r;
  45.  
  46.     /* Register Main Window Class */
  47.  
  48.     hInst = hInstance;
  49.  
  50.     if (!hPrevInstance)
  51.      {
  52.         wc.style = 0;
  53.         wc.lpfnWndProc = WndProc;
  54.         wc.cbClsExtra = 0;
  55.         wc.cbWndExtra = 0;
  56.         wc.hInstance = hInstance;
  57.         wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
  58.         wc.hCursor = LoadCursor( 0, IDC_ARROW );
  59.         wc.hbrBackground = COLOR_WINDOW + 1;
  60.         wc.lpszMenuName = "Example5";
  61.         wc.lpszClassName = "Example5";
  62.         RegisterClass( &wc );
  63.      }
  64.  
  65.  
  66.     /* Initialize terminal IO */
  67.     WinDosIO(WD_INIT,hInstance,0);
  68.  
  69.     /* Create Main Window */
  70.     hwnd = CreateWindow(
  71.                 "Example5",
  72.                 "A Graphics Demo",
  73.                 WS_OVERLAPPEDWINDOW,
  74.                 CW_USEDEFAULT,
  75.                 0,
  76.                 CW_USEDEFAULT,
  77.                 0,
  78.                 0,
  79.                 0,
  80.                 hInstance,
  81.                 NULL
  82.                 );
  83.  
  84.     ShowWindow(hwnd, cmdshow);
  85.  
  86.     /* Create menu window */
  87.     r.top = 0;
  88.     r.left = 0;
  89.     idWindow = CreateWindow("termIO","Graphic Window",
  90.               WS_CHILD ,
  91.               r.left,r.top,640,480,
  92.               hwnd,20,hInstance,0);
  93.     ShowWindow(idWindow,SW_SHOW);
  94.     UpdateWindow(idWindow);
  95. #endif
  96.  
  97.     {
  98.         struct POINTS {
  99.            long x;
  100.            long y;
  101.         } points[5] =
  102.              {{0,0},{620L<<10,0},{620L<<10,420L<<10},
  103.                         {0,420L<<10},{0,0}};
  104.  
  105.     short ratio, times;
  106.  
  107.     do {
  108.         printf("Enter ratio 1-1023 :");
  109.         gets(buffer);
  110.         ratio = atoi(buffer); 
  111.        } while (ratio < 1 || ratio > 1023);
  112.  
  113.     printf("Enter number of times to spiral :");
  114.     gets(buffer);
  115.     times = atoi(buffer); 
  116.  
  117.     if (_setvideomode(_ERESCOLOR) == 0)
  118.       {
  119.         exit(0);
  120.       }
  121.  
  122.  
  123.     _clearscreen(_GCLEARSCREEN);
  124.     _moveto(0,0);
  125.     for (i = 0; i < times; i++)
  126.      {
  127.         _setcolor((i & 3) + 1);
  128.         _lineto((short)(points[1].x >> 10),
  129.             (short)(points[1].y >> 10));
  130.         points[4].x = points[0].x + 
  131.             (((points[1].x - points[0].x) *    ratio) >> 10);
  132.         points[4].y = points[0].y + 
  133.             (((points[1].y - points[0].y) * ratio) >> 10);
  134.         for (j = 0; j < 4; j++)
  135.               points[j] = points[j + 1];
  136.      }
  137.  
  138.     for(;;)
  139.      {
  140.         char c;
  141.         if (((c = getch()) == EOF) || c == 'q') break;
  142.         setpalette(1,random(15)+1);
  143.         setpalette(2,random(15)+1);
  144.         setpalette(3,random(15)+1);
  145.         setpalette(4,random(15)+1);
  146.      }
  147.     WinDosIO(WD_DESTROY,hwnd,0);
  148.     while( GetMessage( &msg, 0, 0, 0 ) != 0 )
  149.          {
  150.         TranslateMessage( &msg );
  151.         DispatchMessage( &msg );
  152.          }
  153.     return 0;
  154.  }
  155. }
  156. #ifdef NOWINDOWS
  157. #else
  158. long far pascal WndProc(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
  159.  {
  160.  
  161.     switch( msg )
  162.         {
  163.     case WM_COMMAND:
  164.         break;
  165.     case WM_SETFOCUS:
  166.         WinDosIO(WD_SETFOCUS,0,0);
  167.         break;
  168.     case WM_CLOSE:
  169.             WinDosIO(WD_DESTROY,hwnd,0);
  170.         return 0;
  171.         case WM_DESTROY:
  172.         PostQuitMessage(0);
  173.             return 0;
  174.         }
  175.  
  176.     return DefWindowProc(hwnd,msg,wParam,lParam);
  177. }
  178.  
  179. #endif
  180.  
  181.